package com.example.com.ddai.test;

import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;

import android.util.Log;

import com.example.com.ddai.others.Source;

public class Images {
	// int[] icons = new int[] { 119, 122, 123, 128, 130, 135, 139, 152, 154,
	// 155,
	// 156, 157, 158, 160, 161, 170, 171, 172, 173, 174, 176, 177, 180,
	// 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 195,
	// 236, 237, 238, 239, 242, 243, 244, 245, 246, 247, 249, 250, 252,
	// 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265,
	// 266, 267, 268, 269, 270, 271, 272, 273, 274, 275, 276, 277, 278,
	// 279, 280, 281, 282, 283, 284, 285, 286, 287, 288, 289, 302, 330,
	// 331, 332, 333, 334, 335, 336, 338, 342, 343, 344, 351, 352, 353,
	// 354, 356, 357, 358, 362, 363, 364, 367, 368, 369, 370, 371, 372,
	// 373, 374, 375, 377, 381, 382, 383, 384, 385, 386, 387, 388, 389,
	// 390, 392, 393, 395, 396, 397, 398, 399, 400, 404, 405, 469, 470,
	// 471, 472, 473, 474, 475, 476, 477, 478, 479, 480, 481, 482, 483,
	// 484, 485, 486, 487, 488, 489, 490, 491, 492, 493, 494, 495, 496,
	// 497, 498, 499, 500, 501, 502, 503, 524, 527, 530, 532, 533, 535,
	// 536, 537, 538, 539, 540, 541, 542, 543, 544, 545, 546, 547, 548,
	// 549, 550, 551, 553, 554, 555, 592, 612, 675, 676, 677, 678, 679,
	// 680, 681, 682, 683, 684, 685, 686, 687, 688, 689, 690, 691, 692,
	// 693, 694, 695, 739, 758, 763, 768, 786, 787, 788, 789, 790, 791,
	// 792, 793, 794, 795, 796, 797, 798, 799, 800, 801, 802, 803, 804,
	// 805, 806, 807, 808, 809, 810, 811, 812, 813, 814, 815, 816, 817,
	// 818, 819, 820, 821, 822, 823, 824, 827, 828, 829, 830, 831, 832,
	// 833, 834, 846, 847, 848, 849, 850, 851, 853, 854, 855, 856, 857,
	// 858, 859, 860, 861, 862, 863, 864, 865, 866, 867, 868, 869, 870,
	// 871, 872, 873, 874, 875, 876, 877, 878, 879, 880, 881, 882, 883,
	// 884, 887, 888, 889, 890, 891, 892, 893, 894, 895, 896, 897, 898,
	// 900, 921, 922, 923, 924, 925, 927, 930, 932, 933, 934, 935, 936,
	// 937, 939, 941, 942, 943, 944, 945, 946, 947, 948, 949, 950, 951,
	// 952, 953, 954, 955, 956, 957, 958, 959, 960, 961, 962, 963, 964,
	// 965, 966, 967, 968, 969, 970, 971, 972, 973, 975, 976, 977, 978,
	// 979, 980, 982, 983, 993, 998};

	int[] icons = new int[] { 119, 120, 121, 122, 125, 126, 129, 130, 131, 132,
			134, 135, 136, 138, 139, 141, 142, 143, 146, 147, 148, 151, 152,
			161, 162, 170, 171, 172, 173, 182, 183, 184, 185, 186, 187, 188,
			189, 190, 191, 192, 193, 195, 236, 237, 238, 239, 240, 241, 242,
			243, 244, 245, 246, 247, 248, 249, 250, 253, 254, 255, 257, 259,
			260, 262, 265, 266, 268, 273, 277, 278, 281, 282, 283, 302, 330,
			331, 332, 333, 334, 335, 336, 337, 338, 339, 340, 341, 342, 343,
			344, 345, 346, 347, 348, 349, 350, 351, 352, 353, 354, 355, 356,
			357, 358, 359, 360, 361, 362, 363, 364, 365, 469, 485, 486, 487,
			488, 489, 490, 491, 492, 493, 494, 495, 496, 497, 498, 500, 501,
			503, 524, 525, 526, 527, 528, 529, 531, 532, 535, 542, 547, 549,
			551, 553, 555, 556, 557, 558, 559, 560, 561, 562, 563, 564, 565,
			566, 592, 612, 645, 646, 647, 648, 649, 650, 651, 652, 653, 654,
			655, 656, 657, 658, 674, 675, 676, 677, 678, 679, 680, 681, 682,
			683, 684, 685, 686, 687, 688, 689, 690, 691, 692, 693, 694, 695,
			696, 697, 698, 699, 700, 701, 702, 703, 704, 705, 706, 707, 708,
			709, 710, 711, 712, 713, 714, 715, 716, 717, 718, 719, 720, 721,
			722, 723, 724, 725, 726, 727, 728, 729, 730, 731, 732, 733, 734,
			735, 736, 737, 738, 739, 740, 741, 742, 743, 744, 745, 746, 747,
			748, 749, 750, 751, 752, 753, 754, 755, 756, 757, 758, 759, 760,
			761, 762, 763, 764, 765, 766, 767, 768, 769, 770, 771, 772, 773,
			774, 775, 776, 777, 778, 779, 780, 781, 782, 783, 784, 785, 786,
			787, 788, 789, 790, 791, 792, 793, 794, 795, 796, 797, 798, 799,
			800, 801, 802, 803, 804, 805, 806, 807, 808, 809, 810, 811, 812,
			813, 814, 815, 816, 817, 818, 819, 820, 821, 822, 823, 824, 825,
			826, 827, 828, 829, 830, 831, 832, 833, 834, 835, 836, 837, 838,
			839, 840, 841, 842, 843, 844, 845, 846, 847, 848, 849, 850, 851,
			853, 854, 855, 856, 857, 858, 859, 860, 861, 862, 863, 864, 865,
			866, 867, 868, 869, 870, 871, 872, 873, 874, 875, 876, 877, 878,
			879, 880, 881, 882, 883, 884, 889, 890, 891, 892, 893, 894, 895,
			896, 897, 898, 921, 922, 923, 924, 925, 927, 928, 929, 930, 931,
			932, 933, 934, 935, 936, 937, 938, 939, 940, 941, 942, 943, 944,
			945, 946, 947, 948, 949, 950, 951, 952, 953, 954, 955, 956, 957,
			958, 959, 960, 961, 962, 963, 964, 965, 966, 967, 968, 969, 970,
			971, 972, 973, 974, 976, 977, 978, 979, 980, 981, 982, 984, 985,
			986, 987, 988, 989, 990, 991, 992, 993, 995, 996, 997};

	ArrayList<Source> sources = new ArrayList<Source>();

	public ArrayList<Source> loadData() {
		sources = new ArrayList<Source>();
		String start = "http://img9.zol.com.cn/desk_pic/mid_433/432";
		String end = ".jpg";
		Source s;
		for (int i : icons) {
			s = new Source();
			s.name = "" + i;
			s.pic = start + i + end;
			sources.add(s);
		}
		return sources;
	}

	public ArrayList<Source> loadData(int until, int count) {
		sources = new ArrayList<Source>();
		String start = "http://desk11.itbulo.com/design/design/160/";
		String end = ".jpg";
		Source s;
		if (until > 0) {
			boolean flag = false;
			int max = count;
			for (int i : icons) {
				if (i == until) {
					flag = true;
				} else {
					if (flag) {
						if (max > 0) {
							max--;
							s = new Source();
							s.name = "" + i;
							s.pic = start + i + end;
							sources.add(s);
						} else {
							flag = false;
							return sources;
						}
					}
				}
			}
		} else {
			int max = count;
			for (int i : icons) {
				if (max-- > 0) {
					s = new Source();
					s.name = "" + i;
					s.pic = start + i + end;
					sources.add(s);
				} else {
					return sources;
				}
			}
		}
		return sources;
	}

	public void testResources() {
		new Thread(new Runnable() {

			@Override
			public void run() {
				int starti = 0;
				int endi = 999;
				String start = "http://img9.zol.com.cn/desk_pic/mid_433/432";
				String end = ".jpg";

				HttpURLConnection urlConnection = null;
				StringBuffer buffer = new StringBuffer();

				for (int i = starti; i < endi; i++) {
					Log.d("DDAI", "I=" + i);
					URL url;
					try {
						url = new URL(start + i + end);
						urlConnection = (HttpURLConnection) url
								.openConnection();
						final InputStream is = urlConnection.getInputStream();
						buffer.append(i + ", ");
					} catch (Exception e) {
					}
				}
				Log.e("DDAI", buffer.toString());
			}
		}).start();
	}
}
